import 'package:flutter/material.dart';
import 'package:ytbusiness/page/message_notice/chat_room/message_text.dart';
import 'package:ytbusiness/page/message_notice/chat_room/message_voice.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

class ChatItem extends StatefulWidget {
  final int type;
  final int messageType;

  const ChatItem({Key key, this.type, this.messageType}) : super(key: key);

  @override
  _ChatItemState createState() => _ChatItemState();
}

class _ChatItemState extends State<ChatItem> {
  @override
  Widget build(BuildContext context) {
    return widget.type % 2 == 0
        ? Container(
            padding: EdgeInsets.only(
                left: setWidth(10),
                right: setWidth(10),
                top: setWidth(10),
                bottom: setWidth(10)),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                //头像
                Container(
                  height: setWidth(54),
                  width: setWidth(54),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage("assets/images/touxiang.png"),
                        fit: BoxFit.cover,
                      ),
                      borderRadius: BorderRadius.circular(30)),
                ),
                SizedBox(
                  width: setWidth(11),
                ),
                //消息类型
                contentType(widget.type)
              ],
            ),
          )
        : Container(
            padding: EdgeInsets.only(
                left: setWidth(10),
                right: setWidth(10),
                top: setWidth(10),
                bottom: setWidth(10)),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                //消息类型
                contentType(widget.type),
                SizedBox(
                  width: setWidth(11),
                ),
                //头像
                Container(
                  height: setWidth(54),
                  width: setWidth(54),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage("assets/images/touxiang.png"),
                        fit: BoxFit.cover,
                      ),
                      borderRadius: BorderRadius.circular(30)),
                ),
              ],
            ),
          );
  }

  // ignore: missing_return
  Widget contentType(int index) {
    switch (index) {
      case 0:
        return MessageText();
      case 1:
        return MessageText();
      case 2:
        return MessageVoice(type: index);
      case 3:
        return MessageVoice(type: index);
      default:
        return MessageText();
    }
  }
}
